﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }

    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}

namespace Task_1
{
    class Program
    {
        public class GenericList<T>
        {
            private Node<T> head;
            private Node<T> tail;

            public GenericList()
            {
                head = tail = null;
            }

            public Node<T> Head
            {
                get =>head; 
            }

            public void Add(T t)
            {
                Node<T> n = new Node<T>(t);
                if (tail == null)
                {
                    head = tail = n;
                }
                else
                {
                    tail.Next = n;
                    tail = n;
                }

            }

            public void Scan(Action<T> action)
            {
                for (Node<T> m = head; m.Next != null; m = m.Next)
                {
                    action(m.Data);
                }
            }
        }

        static void Main(string[] args)
        {
            int sum = 0;
            Random rd = new Random();
            GenericList<int> list = new GenericList<int>();
            for (int i = 0; i < 20; i++)
            {
                list.Add(rd.Next() % 100);
            }
            int max = list.Head.Data;
            int min = list.Head.Data;

            list.Scan(n => Console.WriteLine(n));
            list.Scan(n => sum =sum + n);
            list.Scan(n => { max = max > n ? max : n; });
            list.Scan(n => { min = min < n ? min : n; });

            Console.WriteLine("最大值为 " + max);
            Console.WriteLine("最小值为 " + min);
            Console.WriteLine("总和为 " + sum);

        }
    }
}